package com.heima.behavior.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.behavior.dto.BehaviorDto;
import com.heima.common.dto.ResponseResult;
import com.heima.common.dto.User;
import com.heima.common.enums.AppHttpCodeEnum;
import com.heima.common.util.UserThreadLocalUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.behavior.service.IApReadBehaviorService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * APP阅读行为表 前端控制器
 * </p>
 *
 * @author lj
 * @since 2022-07-05
 */
@RestController
@RequestMapping("/api/v1/read_behavior")
@Api(tags = "APP阅读行为表接口")
@CrossOrigin
public class ApReadBehaviorController{

    @Autowired
    private IApReadBehaviorService apReadBehaviorService;

    /**
     * 保存阅读行为记录
     * @param dto
     * @return
     */
    @PostMapping
    @ApiOperation(value = "保存阅读行为记录", notes = "author:liJie")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "阅读行为记录", required = true, dataType = "BehaviorDto")
    public ResponseResult saveRead(@RequestBody BehaviorDto dto){
        User user = UserThreadLocalUtil.get();
        if(user==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN);
        }
        dto.setUserId(user.getUserId());
        return apReadBehaviorService.saveRead(dto);
    }



}
